package com.isoft.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.isoft.dao.FlightLineDao;
import com.isoft.entity.BeginTime;
import com.isoft.entity.Endplace;
import com.isoft.entity.FlightLine;
import com.isoft.service.IFlightLineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class FlightLineService implements IFlightLineService {
    @Autowired
    FlightLineDao flightLineDao;

    @Override
    public IPage<FlightLine> selectByConPage(Integer currentPage, Integer size, String btime,String city) {
        Page<FlightLine> pageRequest = new Page<>(currentPage, size);
        IPage<FlightLine> flightLine2Page = flightLineDao.selectByCon(pageRequest,btime,city);

        log.error("总记录数" + flightLine2Page.getTotal());
        log.error("总页数" + flightLine2Page.getPages());
        log.error("当前页" + (flightLine2Page.getCurrent()));
        log.error("当前页记录个数" + flightLine2Page.getRecords().size());
        log.error("当前页记录" + flightLine2Page.getRecords());

        return flightLine2Page;
    }

    @Override
    public List<FlightLine> selectAllLine() {

        return flightLineDao.selectAllLine();
    }

    @Override
    public List<FlightLine> checkUnPublicLIne() {
        return flightLineDao.unPublicLine();
    }

    @Override
    public IPage<FlightLine> selectUnPublicLinePage(int currentPage, int size) {
        Page<FlightLine> pageRequest = new Page<>(currentPage, size);
        IPage<FlightLine> flightLinePage = flightLineDao.selectUnPublicPage(pageRequest);

        log.error("总记录数" + flightLinePage.getTotal());
        log.error("总页数" + flightLinePage.getPages());
        log.error("当前页" + (flightLinePage.getCurrent()));
        log.error("当前页记录个数" + flightLinePage.getRecords().size());
        log.error("当前页记录" + flightLinePage.getRecords());

        return flightLinePage;
    }

    @Override
    public List<FlightLine> selectByDay(String day) {
        return flightLineDao.selectByDay(day);
    }

    @Override
    public List<FlightLine> selectByCondition(String starttime, String endtime, String city) {
        return flightLineDao.selectByCondition(starttime,endtime,city);
    }





    @Override
    public Boolean addLine(FlightLine flightLine) {
        flightLine.setIspermit(0);
        return flightLineDao.addLine(flightLine) > 0;
    }

    @Override
    public Boolean deleteLine(Integer id) {
        return flightLineDao.deleteLine(id) > 0;
    }

    @Override
    public List<Endplace> selectByEndplace() {
        return flightLineDao.selectByEndplace();
    }

    @Override
    public List<BeginTime> selectByBeginTime() {
        return flightLineDao.selectByBeginTime();
    }


    @Override
    public Boolean passPermit(Integer id) {
        return flightLineDao.changePermit(id) > 0;
    }

    @Override
    public Boolean updateLine(FlightLine flightLine) {
        return flightLineDao.updateLine(flightLine) > 0;
    }

    @Override
    public IPage<FlightLine> selectAllLinePage(int currentPage, int size) {
        Page<FlightLine> pageRequest = new Page<>(currentPage, size);
        IPage<FlightLine> flightLinePage = flightLineDao.selectPage(pageRequest);

        log.error("总记录数" + flightLinePage.getTotal());
        log.error("总页数" + flightLinePage.getPages());
        log.error("当前页" + (flightLinePage.getCurrent()));
        log.error("当前页记录个数" + flightLinePage.getRecords().size());
        log.error("当前页记录" + flightLinePage.getRecords());

        return flightLinePage;
    }
}
